/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef structures_H
#define structures_H
#ifdef SQL_LIBS
#include "/usr/include/mysql/mysql.h"
#endif
#include "my_limits.h"

/* this structure is used to store all the settings */
typedef struct configuration_struct {
	int daemon;						/* run as a daemon ?? */
	uid_t uid;						/* uid to use while running */
	/* serial connection */
	char generic_location[FILE_NAME_LENGTH];		/* generic location of the probes */
	int is_serial;						/* 1 if the location is a real serial port. 0 for a pipe (for testing purpose)*/
	int num_probes;						/* number of probes too log */
	int probe_index_start;					/* index of the first probe (the "0" in /dev/ttyS0) */
	int file_descriptor_max;				/* maximum index of the opened file descriptors (could be > num_probes) */
	/* mode and sampling rates */
	int activity_data_write_sampling;			/* sampling for data log, activity mode */
	int pulse_data_write_sampling;				/* sampling for data log, pulse mode */
	int pulse_mode;						/* EXIT_SUCCESS if we are in radiation pulse mode */
	int pulse_particule_sub_sampling;			/* sub_sampling rate for pulse mode*/
	int pulse_mode_particules_sampling_count;		/* every ... particules sampling periods, we will write data to file */
	int pulse_mode_particules_sampling_write;		/* every ... particules sampling periods, we will write data to file */
	int file_log;						/* log data to a file (on per probe) */
	char log_file_path[FILE_NAME_LENGTH];			/* path to the data log file */
	int syslog;						/* logging errors using syslog ? */
	#ifdef SQL_LIBS
	/* sql connection */
	MYSQL mysql;						/* MySQL database pointer */
        MYSQL_STMT *mysql_stmt;					/* MySQL statement */
        MYSQL_BIND param[4];					/* MySQL bind data */
	int sql_log;						/* are we going to log data to an SQL server? */
	char sql_host[SQL_PARAMETERS_STRINGS];			/* if logging data to a MySQL server, host name */
	int sql_port;						/* port which is going to be used for MySQL connection */
	char sql_database[SQL_PARAMETERS_STRINGS];		/* if logging data to a MySQL server, database name */
	char sql_table[SQL_PARAMETERS_STRINGS];			/* if logging data to a MySQL server, table name */
	char sql_user[SQL_PARAMETERS_STRINGS];			/* if logging data to a MySQL server, user name */
	char sql_password[SQL_PARAMETERS_STRINGS];		/* if logging data to a MySQL server, password */
	#endif
} configuration_structure;

/* data needed for a probe acquisition */
typedef struct probe_descriptor {
	FILE *log_file;				/* log file associated with this probe */
	char location[FILE_NAME_LENGTH];	/* general location of the probe (like "/dev/ttyS") */
	int number;				/* probe number (like 0 -> it will be /dev/ttyS0) */
	int index;				/* logical number of the probe (this is the n-th probe we are working with) */
	int file_descriptor;			/* file_descriptor of the probe */
	int sensitivity;			/* sensitivity for the calibration of the probe (in cps/mR/h) */
	char display_units[SHORT_STRING];	/* in order to store "cpm" or "raw" for screen display */
	char si_units[SHORT_STRING];		/* in order to store the physical units */
	float conv2rh;				/* factor needed for R/h conversion */
	float conv2display;			/* conversion factor for a nice value on the screen (basically, raw->cpm) */
	float value;				/* number of events recorded by this probe since ... last time in activity recording mode*/
						/* or pulse amplitude in pulse mode */
} probe_descriptor_struct;

#endif
